package com.by.controller;

import com.alibaba.nacos.api.model.v2.Result;
import com.by.bean.OrderItem;
import com.by.core.bean.ResultBean;
import com.by.core.controller.BaseController;
import com.by.service.OrderItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "订单项查询")
@RequestMapping("/api")
public class OrderItemController extends BaseController {


    @Autowired
    OrderItemService orderItemService;

    /**
     * 1.据订单编号获取订单项
     * */
    @GetMapping("/queryOrderItemById")
    @ApiOperation("据订单编号获取订单项")
    public ResultBean queryOrderItemById(int id){
        OrderItem orderItem= orderItemService.getById(id);
        return success("ok",orderItem);
    }

    /**
     * 2.插入订单项
     **/
    @PostMapping("/insertOrderItem")
    @ApiOperation("创建订单项")
    public Result<Boolean> insertOrderItem( @RequestBody OrderItem orderItem) {
        boolean isSaved = orderItemService.save(orderItem);
        return Result.success(isSaved);
    }



}
